home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performUnparent.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  7.8 KB  |  315 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  November 25, 1996
  22. //
  23. //  Description:
  24. //      Ununparent option box script.
  25. //
  26. //  Input Arguments:
  27. //      bool        if true show option box
  28. //                    if false perform command with current values
  29. //  Return Value:
  30. //      None.
  31. //
  32.  
  33. proc setOptionVars (int $forceFactorySettings)
  34. {
  35.     //    Remove flag
  36.     //
  37.     if ($forceFactorySettings || !`optionVar -exists unparentRemove`) {
  38.         optionVar -intValue unparentRemove false;
  39.     }
  40.  
  41.     //    Absolute flag
  42.     //
  43.     if ($forceFactorySettings || !`optionVar -exists unparentPreserve`) {
  44.         optionVar -intValue unparentPreserve true;
  45.     }
  46.  
  47. }
  48.  
  49. global proc unparentSetup (string $parent, int $forceFactorySettings)
  50. {
  51.     int $boolToOption[] = { 1, 2 };
  52.  
  53.     // Retrieve the option settings
  54.     //
  55.     setOptionVars ($forceFactorySettings);
  56.     setParent $parent;
  57.  
  58.     //    Remove flag
  59.     //
  60.     int $rem = `optionVar -q unparentRemove`;
  61.     radioButtonGrp -e -select $boolToOption[$rem] unparentMethod;
  62.  
  63.     //    Absolute flag
  64.     //
  65.     int $preserve = `optionVar -q unparentPreserve`;
  66.     checkBoxGrp -e -en1 (!$rem) -v1 $preserve unparentCheck;
  67. }
  68.  
  69. global proc unparentCallback (string $parent, int $doIt)
  70. {
  71.     int $optionToBool[] = { 0, false, true };
  72.     setParent $parent;
  73.  
  74.     // Set the optionVar's from the control values, and then perform command
  75.     //
  76.  
  77.     //    Remove flag
  78.     //
  79.     int $i = `radioButtonGrp -q -select unparentMethod`;
  80.     optionVar -intValue unparentRemove $optionToBool[$i];
  81.  
  82.     //    Preserve flag
  83.     //
  84.     optionVar -intValue unparentPreserve `checkBoxGrp -q -v1 unparentCheck`;
  85.  
  86.     if ($doIt) {
  87.         performUnparent 0; 
  88.         addToRecentCommandQueue "performUnparent 0" "UnParent";
  89.     }
  90. }
  91.  
  92. //
  93. //  Procedure Name:
  94. //      unparentOptions
  95. //
  96. //  Description:
  97. //        Construct the option box UI.  Involves accessing the standard option
  98. //        box and customizing the UI accordingly.
  99. //
  100. //  Input Arguments:
  101. //      None.
  102. //
  103. //  Return Value:
  104. //      None.
  105. //
  106. proc unparentOptions()
  107. {
  108.     //    Name of the command for this option box.
  109.     //
  110.     string $commandName = "unparent";
  111.  
  112.     //    Build the option box actions.
  113.     //
  114.     string $callback = ($commandName + "Callback");
  115.     string $setup = ($commandName + "Setup");
  116.  
  117.     //    STEP 1:  Get the option box.
  118.     //    ============================
  119.     //
  120.     //    The value returned is the name of the layout to be used as
  121.     //    the parent for the option box UI.
  122.     //
  123.     string $layout = getOptionBox();
  124.     setParent $layout;
  125.     
  126.     //    STEP 2:  Pass the command name to the option box - see STEP 8.
  127.     //    ==============================================================
  128.     
  129.     //    STEP 3:  Activate the default UI template.
  130.     //    ==========================================
  131.     //
  132.     //    Activate the default UI template so that the layout of this 
  133.     //    option box is consistent with the layout of the rest of the 
  134.     //    application.
  135.     //
  136.     setUITemplate -pushTemplate DefaultTemplate;
  137.  
  138.     //    STEP 4: Create option box contents.
  139.     //    ===================================
  140.     //    
  141.     //    This, of course, will vary from option box to option box.    
  142.     
  143.     //    Turn on the wait cursor.
  144.     //
  145.     waitCursor -state 1;
  146.  
  147.     //
  148.     tabLayout -tabsVisible 0 -scrollable 1;
  149.     
  150.     string $parent = `columnLayout -adjustableColumn 1`;
  151.     
  152.     string $onCmd  = "checkBoxGrp -e -en1 true  unparentCheck";
  153.     string $offCmd = "checkBoxGrp -e -en1 false unparentCheck";
  154.  
  155.     radioButtonGrp -numberOfRadioButtons 2
  156.         -label "Unparent Method"
  157.         -label1 "Parent to World"
  158.         -label2 "Remove Instance"
  159.         -on2 $offCmd
  160.         -of2 $onCmd
  161.         unparentMethod;
  162.  
  163.     checkBoxGrp -numberOfCheckBoxes 1
  164.         -label1 "Preserve Position"
  165.         unparentCheck;
  166.  
  167.     //    Turn off the wait cursor.
  168.     //
  169.     waitCursor -state 0;
  170.     
  171.     //    Step 5: Deactivate the default UI template.
  172.     //    ===========================================
  173.     //
  174.     setUITemplate -popTemplate;
  175.  
  176.     //    Step 6: Customize the buttons.  
  177.     //    ==============================
  178.     //
  179.     //    Provide more descriptive labels for the buttons.  This is not 
  180.     //    necessary, but in some cases, for example, a button labelled 
  181.     //    'Create' may be more meaningful to the user than one labelled
  182.     //    'Apply'.
  183.     //
  184.     //    Disable those buttons that are not applicable to the option box.
  185.     //
  186.     //    Attach actions to those buttons that are applicable to the option
  187.     //    box.  Note that the 'Close' button has a default action attached 
  188.     //    to it that will hide the window.  If a a custom action is
  189.     //    attached to the 'Close' button then be sure to call the 'hide the
  190.     //    option box' procedure within the custom action so that the option
  191.     //    box is hidden properly.
  192.  
  193.     //    'Apply' button.
  194.     //
  195.     string $applyBtn = getOptionBoxApplyBtn();
  196.     button -edit
  197.         -label "Unparent"
  198.         -command ($callback + " " + $parent + " " + 1)
  199.         $applyBtn;
  200.  
  201.     //    'Save' button.
  202.     //
  203.     string $saveBtn = getOptionBoxSaveBtn();
  204.     button -edit 
  205.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  206.         $saveBtn;
  207.  
  208.     //    'Reset' button.
  209.     //
  210.     string $resetBtn = getOptionBoxResetBtn();
  211.     button -edit 
  212.         -command ($setup + " " + $parent + " " + 1)
  213.         $resetBtn;
  214.  
  215.     //    Step 7: Set the option box title.
  216.     //    =================================
  217.     //
  218.     setOptionBoxTitle("Unparent Options");
  219.  
  220.     //    Step 8: Customize the 'Help' menu item text.
  221.     //    ============================================
  222.     //
  223.     setOptionBoxHelpTag( "Unparent" );
  224.  
  225.     //    Step 9: Set the current values of the option box.
  226.     //    =================================================
  227.     //
  228.     eval (($setup + " " + $parent + " " + 0));    
  229.     
  230.     //    Step 10: Show the option box.
  231.     //    =============================
  232.     //
  233.     showOptionBox();
  234. }
  235.  
  236. //
  237. //  Procedure Name:
  238. //      assembleCmd
  239. //
  240. //  Description:
  241. //        Construct the command that will apply the option box values.
  242. //
  243. //  Input Arguments:
  244. //      None.
  245. //
  246. proc string assembleCmd()
  247. {
  248.     string $cmd = "unparent";
  249.  
  250.     setOptionVars(false);
  251.  
  252.     string  $cmd      = "parent";
  253.     int        $rm       = `optionVar -q unparentRemove`;
  254.     int        $preserve = `optionVar -q unparentPreserve`;
  255.  
  256.     if ($rm) $cmd += " -rm";
  257.     else     $cmd += " -w";
  258.     if (!$preserve) $cmd += " -r";
  259.  
  260.     return $cmd;
  261. }
  262.  
  263. //
  264. //  Procedure Name:
  265. //      performOptionBoxExample1
  266. //
  267. //  Description:
  268. //        Perform the unparent command using the corresponding 
  269. //        option values.  This procedure will also show the option box
  270. //        window if necessary as well as construct the command string
  271. //        that will invoke the optionBoxExample1 command with the current
  272. //        option box values.
  273. //
  274. //  Input Arguments:
  275. //      0 - Execute the command.
  276. //      1 - Show the option box dialog.
  277. //      2 - Return the command.
  278. //
  279. global proc string performUnparent(int $action)
  280. {
  281.     string $cmd = "";
  282.  
  283.     switch ($action) {
  284.  
  285.         //    Execute the command.
  286.         //
  287.         case 0:
  288.             //    Get the command.
  289.             //
  290.             $cmd = `assembleCmd`;
  291.  
  292.             //    Execute the command with the option settings.
  293.             //
  294.             evalEcho($cmd);
  295.  
  296.             break;
  297.  
  298.         //    Show the option box.
  299.         //
  300.         case 1:
  301.             unparentOptions;
  302.             break;
  303.  
  304.         //    Return the command string.
  305.         //
  306.         case 2:
  307.             //    Get the command.
  308.             //
  309.             $cmd = `assembleCmd`;
  310.             break;
  311.     }
  312.     return $cmd;
  313. }
  314.  
  315.